<template>
  <yd-ls-layout title="积分明细" :onfoot=false :tolfurl="urls">
    <div class="yd-ls-height"></div>
    <yd-cell-group
      :title="items.year_month"
      class="yd-ls-points-detail"
      v-for="(items,index) in list"
      :key="index">
      <yd-cell-item v-for="(datas, ind) in items.items" :key="ind">
						<span slot="left">
							<span>{{ datas.integralDate }}</span>
              <i>{{ datas.integralNumber }}</i>
						</span>
        <span slot="right">{{ datas.detailDescription }}</span>
      </yd-cell-item>


    </yd-cell-group>
    <yd-ls-default v-if="!list.length">暂无积分明细</yd-ls-default>
    <yd-ls-more v-if="total > (pageIndex*pageSize)" @click.native="loadmore()"></yd-ls-more>
  </yd-ls-layout>
</template>

<style>
.yd-ls-points-detail {
  margin-bottom: 0;
}
.yd-ls-points-detail .yd-cell-title {
  padding-top: 0.1rem;
}
.yd-ls-points-detail .yd-cell-left span span {
  display: inline-block;
  width: 2rem;
}
</style>
<script>
import ydLsLayout from "../../../components/yd-ls-layout.vue";
import ydLsContent from "../../../components/yd-ls-content.vue";
import ydLsMore from "../../../components/yd-ls-more.vue";
import ydLsDefault from "../../../components/yd-ls-default.vue";
import { mapGetters } from "vuex";
import api from "../../../axios/api";

export default {
  name: "pointsDetail",
  data() {
    return {
      urls: "index.html#/points",
      list: [],
      pageIndex: 1,
      pageSize: 10,
      total: 0
    };
  },
  computed: {
    ...mapGetters(["getPointsData"])
  },
  created() {
    //TODO:初始化数据
    this.pageIndex = 1 // 重置初始值
    this.getPointsItems()
  },
  methods: {
    init() {},
    getPointsItems(type) {
      this.$dialog.loading.open(api.default_loading_txt);
      this.axios.get(api.points_data,{
          params: {
            pageindex: this.pageIndex,
            pagesize: this.pageSize
          }
        })
          .then(m=>{
            let list_data = m.data
            let year_items = list_data.data.year_items
            let list_len = this.list.length
            this.total = list_data.pageinfo.total
            this.$dialog.loading.close()
            if(type === 'load'){
              let list_year_month = this.list[list_len-1].year_month
              let list_items = this.list[list_len-1].items
              if(list_year_month == year_items[0].year_month){
                  for(let item of year_items[0].items) {
                    list_items.push(item) //把相同年份的数据组合到同一个对象中
                  }
                  this.list = this.list.concat(year_items.splice(1, 1))
                  return
                }
              this.list = this.list.concat(year_items)
              return
            }
            this.list = year_items
          }).catch(err=>{
            this.$dialog.loading.close()
            this.$dialog.alert({mes: JSON.stringify(err)})
          })
      },
      loadmore(){
        this.pageIndex = this.pageIndex+1
        this.getPointsItems('load')
      }
  },
  mounted() {
    this.init();
  },
  components: { ydLsLayout, ydLsContent, ydLsMore, ydLsDefault }
};
</script>
